// pages/serve/serve.js
var app=getApp(),that
Page({

  /**
   * 页面的初始数据
   */
  data: {
    server:[
      { img: '../../../image/se1.png', name: '我的爱车', url:'../../serve/pages/myCar/myCar'},
      { img: '../../../image/se2.png', name: '用车提醒', url:'../../serve/pages/carRemind/carRemind'},
      { img: '../../../image/se3.png', name: '维修履历'},
      { img: '../../../image/se4.png', name: '满意度调查',url:'../../serve/pages/customerMy/customerMy'},
      { img: '../../../image/se5.png', name: '上门取/送车'}
    ],
    bus:[
      { img: '../../../image/bus1.png', name: '事故办案' },
      { img: '../../../image/bus2.png', name: '违章查询', url: '../../serve/pages/violations/violations'},
      { img: '../../../image/bus3.png', name: '缴纳罚款' ,url: '../../serve/pages/fine/fine' },
      { img: '../../../image/bus4.png', name: '用车宝典 ', url: '../../serve/pages/carBook/carBook'},
      { img: '../../../image/bus5.png', name: '年检代办' },
      { img: '../../../image/bus8.png', name: '加油站', url:'../../serve/pages/petrol/petrol'}
    ],
    order:[
      { img: '../../../image/order1.png', name: '一键预约', url:'../../serve/pages/subscribe/subscribe'},
      { img: '../../../image/order2.png', name: '汽车美容' },
      { img: '../../../image/order3.png', name: '一键救援', url: '../../serve/pages/rescue/rescue'},
      // { img: '../../../image/order4.png', name: '大昌出行' },
      { img: '../../../image/dczc.png', name: '大昌租车', appId:'wxcf2154b35b499fe4'}      
    ],
    serveNewsData:[],
    memberId:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    that=this
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    that.getCarNews();
    that.setData({
      memberId: wx.getStorageSync('bizUserInfo').id
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  getCarNews: function () {
    app.getData({
      url: app.api.getCarNews(89, that.data.memberId, 1, 5),
      ok: function (res) {
        console.log(res)
        if (res.statusCode == 200 && res.errMsg == 'request:ok') {
          if (res.data.code == 1) {
            that.setData({
              serveNewsData: res.data.list
            })
          }
        }
      }
    })
  },
  itemClick: function (e) {
    console.log(e)
    wx.navigateTo({
      url: '/page/serve/pages/newsDetails/newsDetails?item=' + encodeURIComponent(JSON.stringify(e.currentTarget.dataset.item)),
    })
  },
  onClick:function(e){
    console.log(e)
    wx.navigateTo({
      url: e.currentTarget.dataset.item.url
    })
  },
  myClick:function(e){
    console.log(e)
    wx.navigateTo({
      url: e.currentTarget.dataset.item.url
    })
  },
  /**贴心服务 */
  aClick:function(e){
    console.log(e)
    if (e.currentTarget.dataset.item.url){
      wx.navigateTo({
        url: e.currentTarget.dataset.item.url
      })
    }else{
      console.log(typeof (e.currentTarget.dataset.item.appId) )
      wx.navigateToMiniProgram({
        appId: e.currentTarget.dataset.item.appId,
        success(res){
          console.log(2)
        },
        fail(res){
          console.log(1)
        }
      })
    }
    
  }
})